package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.letian.record.domain.RecordGenealogyMemberVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordGenealogyMember;
import com.letian.record.service.IRecordGenealogyMemberService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 族谱成员Controller
 * 
 * @author bmz
 * @date 2025-07-20
 */
@RestController
@RequestMapping("/record/genealogy/member")
public class RecordGenealogyMemberController extends BaseController
{
    @Autowired
    private IRecordGenealogyMemberService recordGenealogyMemberService;

    /**
     * 查询族谱成员列表
     */
    ///@PreAuthorize("@ss.hasPermi('record:genealogy.member:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordGenealogyMember recordGenealogyMember)
    {
        startPage();
        List<RecordGenealogyMember> list = recordGenealogyMemberService.selectRecordGenealogyMemberList(recordGenealogyMember);
        return getDataTable(list);
    }

    @GetMapping("/tree/{genealogyId}")
    public AjaxResult tree(@PathVariable("genealogyId")Long genealogyId)
    {
        List<RecordGenealogyMemberVo> list = recordGenealogyMemberService.getMemberTreeByGenealogyId(genealogyId);
        return success(list);
    }


    /**
     * 导出族谱成员列表
     */
    ///@PreAuthorize("@ss.hasPermi('record:genealogy.member:export')")
    @Log(title = "族谱成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordGenealogyMember recordGenealogyMember)
    {
        List<RecordGenealogyMember> list = recordGenealogyMemberService.selectRecordGenealogyMemberList(recordGenealogyMember);
        ExcelUtil<RecordGenealogyMember> util = new ExcelUtil<RecordGenealogyMember>(RecordGenealogyMember.class);
        util.exportExcel(response, list, "族谱成员数据");
    }

    /**
     * 获取族谱成员详细信息
     */
    ///@PreAuthorize("@ss.hasPermi('record:genealogy.member:query')")
    @GetMapping(value = "/{genealogyMemberId}")
    public AjaxResult getInfo(@PathVariable("genealogyMemberId") Long genealogyMemberId)
    {
        return success(recordGenealogyMemberService.selectRecordGenealogyMemberByGenealogyMemberId(genealogyMemberId));
    }

    /**
     * 新增族谱成员
     */
    ///@PreAuthorize("@ss.hasPermi('record:genealogy.member:add')")
    @Log(title = "族谱成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordGenealogyMember recordGenealogyMember)
    {
        return toAjax(recordGenealogyMemberService.insertRecordGenealogyMember(recordGenealogyMember));
    }

    /**
     * 修改族谱成员
     */
    ///@PreAuthorize("@ss.hasPermi('record:genealogy.member:edit')")
    @Log(title = "族谱成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordGenealogyMember recordGenealogyMember)
    {
        return toAjax(recordGenealogyMemberService.updateRecordGenealogyMember(recordGenealogyMember));
    }

    /**
     * 删除族谱成员
     */
    ///@PreAuthorize("@ss.hasPermi('record:genealogy.member:remove')")
    @Log(title = "族谱成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{genealogyMemberIds}")
    public AjaxResult remove(@PathVariable Long[] genealogyMemberIds)
    {
        return toAjax(recordGenealogyMemberService.deleteRecordGenealogyMemberByGenealogyMemberIds(genealogyMemberIds));
    }
}
